<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>企业资源管理系统</title>
    <link rel="shortcut icon" href="favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@6.5.95/css/materialdesignicons.min.css"/>

    <style>
        :root {
            --primary-color: #4CAF50;
            --primary-light: #E8F5E9;
            --primary-dark: #388E3C;
            --gradient-sidebar: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
            --hover-color: #81C784;
            --text-primary: #2E7D32;
            --text-secondary: #616161;
            --border-color: #E0E0E0;
            --sidebar-width: 260px;
            --navbar-height: 64px;
            --background-color: #F9FBF8;
            --sidebar-item-padding: 0 24px;
            --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            min-width: 1366px;
            font-family: 'Inter', -apple-system, sans-serif;
            background: var(--background-color);
            color: var(--text-primary);
            overflow-x: hidden;
        }

        #app {
            display: flex;
            min-height: 100vh;
            position: relative;
        }

        /* 侧边栏样式 */
        .sidebar-container {
            width: var(--sidebar-width);
            background: var(--gradient-sidebar);
            box-shadow: 4px 0 15px rgba(0,0,0,0.05);
            height: 100vh;
            position: fixed;
            z-index: 100;
            border-right: 1px solid rgba(0,0,0,0.05);
            transition: var(--transition);
        }

        .logo {
            height: var(--navbar-height);
            display: flex;
            align-items: center;
            padding: var(--sidebar-item-padding);
            border-bottom: 1px solid rgba(0,0,0,0.05);
            background-color: rgba(255, 255, 255, 0.3);
        }

        .logo i {
            font-size: 28px;
            color: var(--primary-dark);
        }

        .logo span {
            color: var(--primary-dark);
            font-size: 18px;
            font-weight: 600;
            margin-left: 12px;
            white-space: nowrap;
        }

        .el-menu {
            background: transparent !important;
            border-right: 0 !important;
            padding: 16px 0;
        }

        .el-menu-item,
        .el-submenu__title {
            color: var(--text-primary) !important;
            height: 48px;
            line-height: 48px;
            border-radius: 0;
            margin: 0;
            padding: var(--sidebar-item-padding) !important;
            transition: var(--transition);
            font-size: 14px;
        }

        .el-menu-item:hover,
        .el-submenu__title:hover {
            background: rgba(76, 175, 80, 0.1) !important;
        }

        .el-menu-item.is-active {
            background: rgba(76, 175, 80, 0.15) !important;
            border-left: 4px solid var(--primary-color);
            color: var(--primary-dark) !important;
            font-weight: 500;
        }

        .el-submenu .el-menu-item {
            padding-left: 56px !important;
            height: 42px;
            line-height: 42px;
        }

        /* 主内容区域 */
        .main-container {
            margin-left: var(--sidebar-width);
            width: calc(100% - var(--sidebar-width));
            min-height: 100vh;
            transition: var(--transition);
        }

        /* 顶部导航栏 */
        .navbar {
            height: var(--navbar-height);
            background: white;
            box-shadow: 0 2px 8px rgba(0,0,0,0.03);
            padding: 0 24px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: sticky;
            top: 0;
            z-index: 99;
            border-bottom: 1px solid var(--border-color);
        }

        .head-lable span {
            font-size: 16px;
            font-weight: 600;
            color: var(--text-primary);
        }

        .goBack {
            cursor: pointer;
            margin-right: 16px;
            color: var(--text-secondary);
            transition: var(--transition);
        }

        .goBack:hover {
            color: var(--primary-color);
        }

        .goBack img {
            vertical-align: middle;
            margin-right: 4px;
        }

        /* 右侧用户菜单 */
        .right-menu {
            display: flex;
            align-items: center;
        }

        .avatar-wrapper {
            background: rgba(76, 175, 80, 0.1);
            color: var(--text-primary);
            padding: 8px 16px;
            border-radius: 8px;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
            border: 1px solid rgba(76, 175, 80, 0.2);
            cursor: pointer;
            transition: var(--transition);
        }

        .avatar-wrapper:hover {
            background: rgba(76, 175, 80, 0.2);
        }

        .avatar-wrapper i {
            font-size: 18px;
        }

        .outLogin {
            margin-left: 15px;
            font-size: 22px;
            cursor: pointer;
            transition: var(--transition);
            color: var(--text-secondary);
        }

        .outLogin:hover {
            color: #f56c6c;
            transform: scale(1.1);
        }

        /* 主内容区域 */
        .app-main {
            padding: 24px;
            min-height: calc(100vh - var(--navbar-height));
        }

        .c_iframe {
            width: 100%;
            height: calc(100vh - var(--navbar-height) - 48px);
            border: none;
            border-radius: 8px;
            background: white;
            border: 1px solid var(--border-color);
            box-shadow: var(--card-shadow);
        }

        /* 图标样式 */
        .mdi {
            font-size: 20px;
            margin-right: 12px;
            vertical-align: middle;
            color: var(--text-primary);
        }

        .el-menu-item [class^=mdi],
        .el-submenu__title [class^=mdi] {
            margin-right: 12px;
        }

        /* 加载状态 */
        .divTmp {
            height: calc(100vh - var(--navbar-height));
            background: rgba(255, 255, 255, 0.8);
        }

        /* 滚动条 */
        .scrollbar-wrapper {
            overflow-x: hidden !important;
        }

        .el-scrollbar__bar.is-vertical {
            right: 0px;
        }

        .el-scrollbar {
            height: 100%;
        }

        /* 折叠菜单 */
        .el-menu--collapse {
            width: 64px;
        }

        .el-menu--collapse .el-submenu__title span,
        .el-menu--collapse .el-menu-item span {
            display: none;
        }

        .el-menu--collapse .el-submenu__title .el-submenu__icon-arrow {
            display: none;
        }
    </style>
</head>

<body>
<div id="app">
    <div class="sidebar-container">
        <div class="logo">
            <i class="mdi mdi-school"></i>
            <span>企业资源管理系统</span>
        </div>

        <el-menu
                :default-active="defAct"
                :unique-opened="false"
                :collapse-transition="false"
                style="max-height: calc(100vh - var(--navbar-height));overflow-y: auto;">
            <div v-for="item in menuList" :key="item.id">
                <el-submenu :index="item.id" v-if="item.children && item.children.length>0">
                    <template slot="title">
                        <i class="mdi" :class="item.icon"></i>
                        <span>{{item.name}}</span>
                    </template>
                    <el-menu-item
                            v-for="sub in item.children"
                            :index="sub.id"
                            :key="sub.id"
                            @click="menuHandle(sub,false)"
                    >
                        <i class="mdi" :class="sub.icon"></i>
                        <span slot="title">{{sub.name}}</span>
                    </el-menu-item>
                </el-submenu>
                <el-menu-item v-else :index="item.id" @click="menuHandle(item,false)">
                    <i class="mdi" :class="item.icon"></i>
                    <span slot="title">{{item.name}}</span>
                </el-menu-item>
            </div>
        </el-menu>
    </div>

    <div class="main-container">
        <div class="navbar">
            <div class="head-lable">
                <span v-if="goBackFlag" class="goBack" @click="goBack()">
                    <img src="images/icons/btn_back@2x.png" alt=""/> 返回
                </span>
                <span>{{headTitle}}</span>
            </div>
            <div class="right-menu">
                <div class="avatar-wrapper">
                    <i class="mdi mdi-account"></i>
                    {{ userInfo.name }}
                </div>
                <i class="mdi mdi-logout outLogin" @click="logout"></i>
            </div>
        </div>

        <div class="app-main" v-loading="loading">
            <div class="divTmp" v-show="loading"></div>
            <iframe
                    id="cIframe"
                    class="c_iframe"
                    name="cIframe"
                    :src="iframeUrl"
                    width="100%"
                    height="auto"
                    frameborder="0"
                    v-show="!loading"
            ></iframe>
        </div>
    </div>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="plugins/axios/axios.min.js"></script>
<script src="js/request.js"></script>
<script src="api/login.js"></script>

<script>
    // JavaScript部分保持不变
    new Vue({
        el: '#app',
        data() {
            return {
                defAct: '1',
                menuActived: '1',
                userInfo: {},
                /*左侧导航栏数据*/
                menuList: [
                    {
                        id: '1',
                        name: '首页',
                        url: 'page/hello/hello.html',
                    },
                    {
                        id: '2',
                        name: '人员管理',
                        url: 'page/user2/index.html',
                    },
                    // {
                    //     id: '3',
                    //     name: '销售管理',
                    //     url: 'page/sale/index.html',
                    // },
                    {
                        id: '4',
                        name: '客户管理',
                        url: 'page/customer/index.html',
                    },
                    {
                        id: '5',
                        name: '雇员管理',
                        url: 'page/employee/index.html',
                    },
                    {
                        id: '6',
                        name: '库存管理',
                        url: 'page/inventory/index.html',
                    },
                    {
                        id: '7',
                        name: '库存调拨',
                        url: 'page/transfer/index.html',
                    },
                    {
                        id: '8',
                        name: '任务管理',
                        url: 'page/task/index.html',
                    },
                    // {
                    //     id: '9',
                    //     name: '项目管理',
                    //     url: 'page/project/index.html',
                    // },
                    // {
                    //     id: '10',
                    //     name: '采购管理',
                    //     url: 'page/purchaseOrder/index.html',
                    // },
                    {
                        id: '11',
                        name: '日志审批',
                        url: 'page/document/document.html',
                    },
                    {
                        id: '12',
                        name: '日志撰写',
                        url: 'page/log/log.html',
                    },
                ],
                iframeUrl: 'page/hello/hello.html',
                headTitle: '首页',
                goBackFlag: false,
                loading: true,
                timer: null
            }
        },
        computed: {},
        created() {
            const userInfo = window.localStorage.getItem('userInfo');
            if (userInfo) {
                this.userInfo = JSON.parse(userInfo);
            }
            if (this.userInfo.roleId === 3) {
                this.menuList = [
                    {
                        id: '1',
                        name: '首页',
                        url: 'page/hello/hello.html',
                    },

                    {
                        id: '4',
                        name: '库存调拨',
                        url: 'page/transfer/index.html',
                    },
                    {
                        id: '6',
                        name: '日志撰写',
                        url: 'page/log/log.html',
                    },
                ];
            }
            this.closeLoading()
        },
        beforeDestroy() {
            this.timer = null;
            clearTimeout(this.timer);
        },
        mounted() {
            window.menuHandle = this.menuHandle;
        },
        methods: {
            logout() {
                logoutApi().then((res) => {
                    if (res.code === 1) {
                        var b = confirm("是否退出登录？");
                        if (b) {
                            /*从本地栈内移除数据*/
                            localStorage.removeItem('userInfo');
                            window.location.href = 'page/login/login.html';
                        }
                    }
                })
            },
            goBack() {
                const menu = this.menuList.find(item => item.id === this.menuActived);
                this.menuHandle(menu, false)
            },
            menuHandle(item, goBackFlag) {
                this.loading = true;
                this.menuActived = item.id;
                this.iframeUrl = item.url;
                this.headTitle = item.name;
                this.goBackFlag = goBackFlag;
                this.closeLoading()
            },
            closeLoading() {
                this.timer = null;
                this.timer = setTimeout(() => {
                    this.loading = false
                }, 1000)
            }
        }
    })
</script>
</body>
</html>